import store from "../store";
import { hf } from "../util";
export const Onfun = (userName) => {

  try{
    window.socket.on(`${userName}`, function (data) {
      console.log(userName + ":", data);
      store.state.ReceiveMessage = new Date().getTime();
      if (store.state.msgFrom == data.fromName) {
        store.state.msgList.push({
          id:data.id,
          turnoverTime: new Date().getTime(),
          fromName: data.fromName,
          msgBody: data.msgBody,
          headPortrait: data.headPortrait,
        });
      }
      if (window.Notification && Notification.permission !== "denied") {
        Notification.requestPermission(function (status) {
          var n = new Notification("收到：" + data.userNickname, {
            body: data.msgBody,
            icon: data.headPortrait,
          });
          n.onshow = function () {
            //自动关闭
            setTimeout(n.close.bind(n), 10000);
          };
          n.onclick = function () {
            hf("im", data);
          };
        });
      }
  
      
    });
  }catch(e){

  }





};
